package com.hzhr.iot.huaweiiot.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.huaweiiot.controller.base.BaseController;
import com.hzhr.iot.huaweiiot.model.command.postCommand.PostCommandModel;
import com.hzhr.iot.huaweiiot.model.command.postCommand.PostCommandResponse;
import com.hzhr.iot.huaweiiot.service.CommandService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "command", description = "命令相关服务")
@RestController
@RequestMapping(value = "")
public class CommandController extends BaseController {
    @Autowired
    CommandService commandService;

    //region /postCommand POST
    //region swagger响应码 : postCommand
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : postCommand
    @ApiOperation(value="发送命令", notes="发送命令  \n范围 : 系统  \n步骤 :  \n1. 向华为iot平台上的指定设备发送命令; (√)  \n",produces = "application/json")
    //endregion
    //region swagger参数 : postCommand
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : postCommand
    @RequestMapping(value = "/postCommand", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<PostCommandResponse> postCommand(@RequestParam @ApiIgnore Map<String, Object> query,
                                                           @RequestBody PostCommandModel body) throws ServiceException {
        PostCommandResponse responseBody = commandService.postCommand(initHeader(), query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
}












